package com.tjec.project.mdmSynchronous.dao.impl;

import com.tjec.common.utils.StringUtils;
import com.tjec.project.mdmSynchronous.dao.ProjectDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @wjq
 * @date2019/12/6
 */
@Service
public class ProjectDaoImpl implements ProjectDao {

    @Autowired
    private JdbcTemplate primaryJdbcTemplate;

    @Override
    public List<Map<String, Object>> getProjectList(String projectLeader,String projectLeaderNo,String projectGlobalId,long max) {

       String sql = "SELECT [项目全局ID] as projectGlobalId,项目名称 as name ,项目代码 as code,\n" +
               "[项目实施状态] as status ,[计划开始服务日期] as startDate,\n" +
               "[项目执行部门] as executeDept,项目所在公司 as projectCompany,\n" +
               "项目负责人 as projectLeader,项目负责人代码 projectLeaderNo,\n" +
               "建设单位名称 party,[项目总投资_万元] as investment,\n" +
               "[数据有效性] as isValid,CONVERT(BIGINT,项目时间戳) as timestamp,\n" +
               "[服务类别] as serviceType,[前期咨询服务内容] as engineeringConsultingService,\n" +
               "[招标代理服务内容] as biddingAgencyService,[造价咨询服务内容] as costConsultingService,\n" +
               "[项目管理服务内容] as projectManagementService,[工程监理服务内容] as projectSupervisionService,\n" +
               "[设备监理服务内容] as equipmentSupervisionService,[检测服务服务内容] as testingService,\n" +
               "[环境咨询服务内容] as eiaQualificationService,[其它咨询服务内容] as otherConsultingTechnicalService,\n" +
               "[结项情况] as closureSituation,[信息咨询服务内容] as informationConsultingService,\n" +
               "[专项咨询服务内容] as specialConsultingService,[设计咨询服务内容] as designConsultingService,\n" +
               "[结项情况] as closureSituation,[项目所在地区] as area,[服务内容备注] as mainServiceContent,[项目规模描述] as content\n" +
               "FROM [TO_EC_实施台帐_项目实施] WHERE 1=1 ";
       if(StringUtils.isNotBlank(projectLeader)){
           sql=sql +" and 项目负责人='"+projectLeader+"'";
       }
        if(StringUtils.isNotBlank(projectLeaderNo)){
            sql=sql +" and 项目负责人代码='"+projectLeaderNo+"'";
        }
        if(StringUtils.isNotBlank(projectGlobalId)){
            sql=sql +" and 项目全局ID='"+projectGlobalId+"'";
        }
        if(max>0){
            sql =sql+" and CONVERT(BIGINT,项目时间戳)>"+max;
        }
        if(max==0){
            sql =sql+" and 项目所在公司='同济咨询'";
        }
        List<Map<String, Object>>  projectList = primaryJdbcTemplate.queryForList(sql);
        return projectList;
    }
}
